from omegaconf import DictConfig, OmegaConf
from typing import Dict, Any

# 模块级全局变量
_app_config = None

def _convert_bool_values( config_dict: Dict[str, Any]) -> Dict[str, Any]:
        """递归转换配置中的布尔值字符串"""
        result = {}
        for key, value in config_dict.items():
            if isinstance(value, dict):
                result[key] = _convert_bool_values(value)
            elif isinstance(value, str):
                # 转换布尔值字符串
                if value.lower() == 'true':
                    result[key] = True
                elif value.lower() == 'false':
                    result[key] = False
                else:
                    result[key] = value
            else:
                result[key] = value
        return result
    
def initialize_config(cfg: DictConfig):
    """初始化全局配置"""
    global _app_config
    _app_config = _convert_bool_values(OmegaConf.to_container(cfg, resolve=True))

def get_config():
    """获取全局配置"""
    if _app_config is None:
        raise RuntimeError("Configuration not initialized. Call initialize_config() first.")
    return _app_config

# # 可选：提供快捷访问方法
# def get_minio_config():
#     return get_config()['minio']

# def get_ollama_config():
#     return get_config()['ollama']